<template>
	<div class="container">
		<h3 class="header-title clearfix">
			<span></span>
			<p>雇主管理</p>
		</h3>
		<!-- 导航栏 -->
		<!-- <comNavTabs :navList="navList"></comNavTabs> -->
		<!-- 搜索条件：注册时间，用户名，电话等 -->
		<comSearch ref="search" @searchList="getDataList" :options="searchList"></comSearch>
		<!-- 数据展示的列表 -->
		<comTable :options="tableList" @openPar="openParDialog" @openLogs="openLogsDialog"
			@openBlock="openBlockDialog" @openRemind="openRemindDialog"
		></comTable>
		<!-- 分页器 -->
		<div class="pageBox">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="pageChange"
				:current-page="cur"
				:page-sizes="[10, 20, 30, 50, 100]"
				:page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="totalNum"
				background
			></el-pagination>
		</div>
		<!-- 提醒操作弹窗 -->
		<praFeedback ref="remind" @subRemind="submitRemind" :options="remind"></praFeedback>
		<!-- 拉黑操作弹窗 -->
		<praUnreported ref="block" @subBlock="submitBlock" :options="block" ></praUnreported>
		<!-- 认证详情弹窗 -->
		<empPardialog :options="par" ref="parDialog"></empPardialog>
		<!-- 雇主日志弹窗 -->
		<empEmployerLogsDialog ref="logsDialog" @flip="openLogsDialog" :options="logs"></empEmployerLogsDialog>
	</div>
</template>

<script>
import jobsJson from "../../assets/jobs.json"
export default {
	components:{
		comNavTabs: () => import("../common/comNavTabs.vue"),
		comSearch: () => import("../common/comSearch.vue"),
		comTable: () => import("../common/comTable.vue"),
		empPardialog: () => import("../common/empPardialog.vue"),
		empEmployerLogsDialog: () => import("../common/empEmployerLogsDialog.vue"),
		praFeedback: () => import("../common/praFeedback.vue"),
		praUnreported: () => import("../common/praUnreported.vue")
	},
	data(){
		return {
			particularsDialog:true,		//是否显示认证详情弹窗
			userinfo:{},				//当前登录账户的人员信息
			/* 搜索栏数据 */
			searchList:{
				noTime:true,			//有没有时间
				noTelphone:true,		//有没有电话
				noUser:true,			//有没有实名用户名
				noSalary:false,			//有没有薪资待遇
				noEmployer:false,		//有没有雇主
				noCity:true,			//有没有所在地
				noPosition:false,		//有没有职位名称
			},
			/* 保留下来的搜索栏的数据 */
			searchData:{},
			/* 表格数据 */
			tableList:{
				list:[
					{title:'雇主姓名',prop:'name',isClick:false},
					{title:'手机号',prop:'telnum',isClick:false},
					{title:'区域',prop:'region',isClick:false},
					{title:'认证时间',prop:'workdate',isClick:false},
					{title:'认证详情',prop:'particulars',isClick:true,eventName:'openPar'},
					{title:'雇主日志',prop:'employerLogs',isClick:true,eventName:'openLogs'}
				],
				noOperation:true,	//是否有操作项
				operation:[			//操作项内容
					{name:'拉黑',isBtn:true,title:'openBlock'},
					{name:'提醒',isBtn:true,title:'openRemind'}
				],
				data:[				//请求到的表格数据
					/* {
						employer: '谢镔',								//雇主
						telphone: '16666666666',						//手机号
						region: '上海市普陀区金沙江路 1518 弄',			//区域
						attestation: '2016-05-02 11:30',				//认证时间
						particulars: '查看',								//认证详情
						employerLogs: '查看'								//雇主日志
					} */
				]
			},
			/* 分页功能数据 */
			cur:1,
			pageSize: 10,
			totalNum: 0,		//总共有多少条数据,根据这个数据去适配页数
			/* 认证详情数据 */
			par:{
				parDialog:true,							//是否显示弹窗
				name:"谢镔",								//姓名
				id:134845124845151,						//身份证号
				register:"上海市闵行区啥啥路",				//户籍
				presentAddress:"上海市徐汇区啥啥路",		//现住址
				imgList:[
					{src:require('../../assets/img/loginbg.png')},
					{src:require('../../assets/img/loginbg.png')}
				],
				xxx:'xxx'
			},
			/* 雇主日志数据 */
			logs:{
				userinfo:{},										//当前雇主信息
				title:'雇主日志',
				list:[
					{title:'招聘岗位',prop:'jobTitle',isClick:false},
					{title:'薪资区间',prop:'payRanges',isClick:false},
					{title:'发布时间',prop:'updateTime',isClick:false},
					{title:'招聘状态',prop:'shelvesType',isClick:false},
					{title:'支付金额',prop:'aggregateScore',isClick:false},
					{title:'支付状态',prop:'paystatus',isClick:false},
					{title:'评价得分',prop:'evaluate',isClick:false}
				],
				noOperation:false,	//是否有操作项
				data:[				//请求到的表格数据
					/* {
						jobTitle: '月嫂',								//招聘岗位
						payRanges: '6k-7k',								//薪资区间
						updateTime: '2020-03-09 11:30',					//发布时间
						shelvesType: '招聘中',							//招聘状态
						aggregateScore: '1400',							//支付金额
						payStatus: '待支付',								//支付状态
						evaluate: '一般',								//评价得分
						iconUrl:require('../../assets/img/select.png')	//评价得分图标
					} */
				],
				cur:1,					//当前是第几页
				pageSize: 10,			//每页显示多少条数据
				totalNum: 0				//数据条数
			},
			/* 提醒弹窗数据 */
			remind:{
				userinfo:{},
				title:"提醒",						//弹窗标题
				noNav:false,						//是否有选项
				eventName:'subRemind'				//提交事件的名称
			},
			/* 拉黑弹窗数据 */
			block:{
				userinfo: {},						//当前需要进行提醒的用户信息
				title:'拉黑',
				linefeedPre:'确认拉黑该雇主',
				subCon:'确认拉黑',
				eventName:'subBlock',
				modal:true,				
			}
		}
	},
	created(){
		// this.totalNum = this.tableList.data.length;
		this.userinfo = JSON.parse(localStorage.getItem('userinfo'));
		this.getDataList();
	},
	methods:{
		//当前页是第几页,点击的第几页的时候调用这个函数
		pageChange(p) {
			// 点击的时候传过来一个参数，这个参数就是所点击的当前页数，
			// 然后把这个当前页数转换成字符串形式赋值给page，
			// 然后把page这个参数传给search这个方法
			console.log(p);
			this.cur = p;
			this.getDataList(this.searchData);
		},
		//每页有多少条,10,20,50等,点击选择的时候调用这个方法
		handleSizeChange (val) {
			console.log(val);
			this.pageSize = val;
			this.getDataList(this.searchData);
		},
		openParDialog(data){
			console.log(data);
			this.$refs.parDialog.open();
		},
		// 获取数据列表
		getDataList(data){
			console.log(data);
			this.searchData = data;
			let params = {
				pageSize: this.pageSize,
				pageNum: this.cur
			};
			if(data != undefined){
				if(data.startdate != undefined && data.startdate != '' && data.startdate != null){
					params.startDate = data.startdate;
				}
				if(data.enddate != undefined && data.enddate != '' && data.enddate != null){
					params.endDate = data.enddate;
				}
				if(data.phone != undefined && data.phone != '' && data.phone != null){
					params.telnum = data.phone;
				}
				if(data.name != undefined && data.name != '' && data.name != null){
					params.name = data.name;
				}
				if(data.province != undefined && data.province != '' && data.province != null){
					params.province = data.province;
				}
				if(data.city != undefined && data.city != '' && data.city != null){
					params.city = data.city;
				}
				if(data.county != undefined && data.county != '' && data.county != null){
					params.area = data.county;
				}
			}
			console.log(params);
			this.$houseAxios.post('/housekeeping/Employer/selectBasicInfoListGz',params).then(res => {
				console.log(res);
				if(res.data.code === 1000){
					let result = res.data.data;
					this.totalNum = parseInt(result.totalNum);
					this.tableList.data.splice(0);
					result.list.forEach(item => {
						item.region = item.province + '-' + item.city + '-' + item.area;
						this.tableList.data.push(item);
					})
				}
			})
		},
		// 打开拉黑弹窗
		openBlockDialog(data){
			console.log(data);
			this.block.useinfo = data;
			this.$refs.block.open();
		},
		// 确认拉黑雇主
		submitBlock(){
			if(this.block.userinfo.deleted === '0'){
				let deleted = '1';
			}else{
				let deleted = '0';
			}
			this.$houseAxios.post('/housekeeping/Employer/deleteEmployer',{userId:this.block.userinfo.userId,deleted: deleted}).then(res => {
				console.log(res);
				if(res.data.code === 1000){
					this.$message({
						message: '拉黑成功！',
						type: 'success'
					})
				}else{
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
			this.$refs.block.close();
		},
		// 打开提醒模板
		openRemindDialog(data){
			console.log(data);
			this.remind.userinfo = data;
			this.$refs.remind.open();
		},
		// 提交提醒信息
		submitRemind(data){
			console.log(data);
			this.$houseAxios.post('/housekeeping/message/remind',{
				userid: this.remind.userinfo.userId,
				remindcontent: data.textarea,
				remark1: 0
			}).then(res => {
				console.log(res);
				if(res.data.code === 1){
					this.$message({
						message: '提醒成功!',
						type: 'success'
					})
				}else{
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
			this.$refs.remind.close();
		},
		// 打开雇主模板
		openLogsDialog(data){
			let params = {
				userId: data.userId,
				pageNum: this.logs.cur,
				pageSize: this.logs.pageSize
			}
			this.$houseAxios.post('/housekeeping/Employer/selectEmployerAdminList',params).then(res => {
				console.log(res);
				if(res.data.code === 1000){
					// this.$set(this.logs,'totalNum',res.data.data.totalNum);
					this.logs.totalNum = JSON.parse(res.data.data.totalNum);
					let result = res.data.data;
					this.logs.data.splice(0);
					result.elist.forEach(item => {
						jobsJson.jobNameList.forEach(item1 => {
							if(item1.key == item.jobTitle){
								item.jobTitle = item1.value;
							}
						})
						if(item.status == '1'){
							item.payRanges = item.payFloor + '-' + item.payUpper + '元/月';
						}else{
							item.payRanges = item.wagePay + '元/小时';
						}
						
						if(item.shelvesType == 0){
							item.shelvesType = '招聘中';
						}else if(item.shelvesType == 1){
							item.shelvesType = '平台下架';
						}else if(item.shelvesType == 2){
							item.shelvesType = '雇主下架';
						}
						if(item.evaluate == 1){
							item.evaluate = '一般';
						}else if(item.evaluate == 2){
							item.evaluate = '良好';
						}else if(item.evaluate == 3){
							item.evaluate = '优秀';
						}
						if(item.paystatus == 0){
							item.paystatus = '待支付';
						}else if(item.paystatus == 1){
							item.paystatus = '已支付';
						}
						this.logs.data.push(item);
					})
				}
			})
			this.$refs.logsDialog.open();
		}
	}
}
</script>

<style scoped="scoped">
.container{
	background-color: #fff;
	height: 100%;
	padding-left: 20px;
}
.header-title{
	padding: 0 0 20px 0;
	border-bottom: 1px solid #D2D2D2;
}
.header-title span{
	width: 15px;
	height: 30px;
	background-color: #0064E4;
	margin-right: 20px;
	float: left;
}
.header-title p{
	float: left;
	font-weight: bold;
	line-height: 30px;
}
.pageBox{
	margin-top: 20px;
}
</style>
